﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class DeliverGoodsManagement_AddSuggestion : System.Web.UI.Page
{
    private string Code
    {
        get
        {
            return Request.QueryString["Code"] != null ? Request.QueryString["Code"].ToString() : "";
        }
    }

    private string OrderStateTypeCode
    {
        get
        {
            return Request.QueryString["stCode"] != null ? Request.QueryString["stCode"].ToString() : "";
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        Check.CheckPermission("500100");
        if (!IsPostBack)
        {
            BindDropSuggestionType();
        }
    }

    private void BindDropSuggestionType()
    {
        dropSuggestionType.DataSource = new BLL.STATETYPE().GetAllList();
        dropSuggestionType.DataTextField = "ST_NAME";
        dropSuggestionType.DataValueField = "ST_CODE";
        dropSuggestionType.DataBind();

        for (int i = 0; i < dropSuggestionType.Items.Count; i++)
        {
            if (dropSuggestionType.Items[i].Value == this.OrderStateTypeCode)
            {
                dropSuggestionType.SelectedIndex = i;
                //dropSuggestionType.Enabled = false;
                break;
            }
        }
    }


    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (!Check.CheckPermission("500100", "00021"))
        {
            Share.Alert(this.Page, "无权操作"); return;
        }
        if (dropSuggestionType.Items.Count > 0)
        {
            Model.ORDERNOTE suggestion = new Model.ORDERNOTE();
            suggestion.ON_BILLNO = this.Code;
            suggestion.ON_USERCODE = Share.UserValue(0);
            suggestion.ON_TIME = DateTime.Now;
            suggestion.ON_NOTETYPE = dropSuggestionType.SelectedItem.Value;
            suggestion.ON_NOTE = txtSuggestion.Text.Trim();

            Model.ORDERDOC order = new BLL.ORDERDOC().GetModel(this.Code);
            if (order != null)
            {
                order.ORDER_STATETYPECODE = dropSuggestionType.SelectedItem.Value;
                new BLL.ORDERDOC().Update(order);
            }

            if (new BLL.ORDERNOTE().Add(suggestion) > 0)
            {
                Share.InsertLog("500100", "00021");
                Response.Write("<script>alert('添加意见成功！');location.href='InvoiceDetails.aspx?Code=" + this.Code + "'</script>");
            }
            else
            {
                Share.Alert(this.Page, "提交意见时出现错误，请重新添加！");
            }
        }
    }
}
